package 笔试.新凯来;

import java.util.HashMap;
import java.util.Scanner;

// 300
public class 互送礼物 {
    /*
        5
        dave
        laura
        owen
        vick
        amr
        
        dave
        200 3  500 2
        laura
        owen
        vick
        
        owen
        500 1  66  75
        dave
        
        amr
        150 2
        vick
        owen
        
        laura  66
        0 2
        amr
        vick
        
        vick
        0 0    66 75
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        HashMap<String, Integer> map = new HashMap<>();
        String[] name = new String[n];
        for (int i = 0; i < n; i++) {
            String line = sc.nextLine();
            name[i] = line;
            map.put(line, i);
        }
        int[] send = new int[n];
        int[] receive = new int[n];
        for (int t = 0; t < n; t++) {
            String line = sc.nextLine();
            String[] split = sc.nextLine().split(" ");
            int num = Integer.parseInt(split[0]);
            send[map.get(line)] = num;
            int m = Integer.parseInt(split[1]);
            for (int i = 0; i < m; i++) {
                String to = sc.nextLine();
                receive[map.get(to)] += num / m;
            }
            if (m != 0) receive[map.get(line)] += num % m;
        }
        for (int i = 0; i < n; i++) {
            System.out.println(name[i] + " " + (receive[i] - send[i]));
        }

    }
}
